from django.db import models


# Create your models here.

class Province(models.Model):
    """省级"""
    name = models.CharField(max_length=10, verbose_name='省名称')
    code = models.CharField(max_length=20, verbose_name='省id')

    class Meta:
        db_table = 'province'
        verbose_name = "省"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class City(models.Model):
    """市(市辖区)"""
    province = models.ForeignKey(Province, on_delete=models.CASCADE, verbose_name='省', related_name='province')
    name = models.CharField(max_length=20, verbose_name='市(市辖区)')
    code = models.CharField(max_length=20, verbose_name='市(市辖区)id')

    class Meta:
        db_table = 'city'
        verbose_name = "市(市辖区)"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Country(models.Model):
    """县(区、市)"""
    city = models.ForeignKey(City, on_delete=models.CASCADE, verbose_name='市(市辖区)', related_name='city')
    name = models.CharField(max_length=20, verbose_name='县(区、市)')
    code = models.CharField(max_length=20, verbose_name='县(区、市)id')

    class Meta:
        db_table = 'country'
        verbose_name = "县(区、市)"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Town(models.Model):
    """镇(街道)"""
    country = models.ForeignKey(Country, on_delete=models.CASCADE, verbose_name='县(区、市)', related_name='country')
    name = models.CharField(max_length=20, verbose_name='镇(街道)')
    code = models.CharField(max_length=20, verbose_name='镇(街道)id')

    class Meta:
        db_table = 'town'
        verbose_name = "镇(街道)"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
